package com.ydh.company.controller;

import com.ydh.company.dto.ResponseData;
import com.ydh.company.dto.ResultData;
import com.ydh.company.pojo.Client;
import com.ydh.company.pojo.ClientLevel;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("clientLevel")
@Api(value = "客户级别接口",tags = "客户级别接口API（6个）HKill")
public class ClientLevelController {


    @PostMapping(value = "queryClientLevel")
    @ResponseBody
    @ApiOperation(value = "1查询客户级别接口", notes = "展示所有客户级别信息", httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败")}
    )
    public ResultData queryClientLevel(@RequestBody @ApiParam(name = "ClientLevel", value = "显示所有客户级别名称", required = true) ClientLevel clientLevel) {


        List<ClientLevel> clientLevelList = new ArrayList<>();

        ClientLevel clientLevel1 = new ClientLevel();
        clientLevel1.setClientLevelId(1);
        clientLevel1.setClientLevelName("普通代理");
        clientLevel1.setClientDiscount(1.0);
        clientLevel1.setFlag(1);

        ClientLevel clientLevel2 = new ClientLevel();
        clientLevel2.setClientLevelId(2);
        clientLevel2.setClientLevelName("一级代理");
        clientLevel2.setClientDiscount(0.8);
        clientLevel2.setFlag(0);

        ClientLevel clientLevel3 = new ClientLevel();
        clientLevel3.setClientLevelId(3);
        clientLevel3.setClientLevelName("二级代理");
        clientLevel3.setClientDiscount(0.7);
        clientLevel3.setFlag(0);

        ClientLevel clientLevel4 = new ClientLevel();
        clientLevel4.setClientLevelId(4);
        clientLevel4.setClientLevelName("三级代理");
        clientLevel4.setClientDiscount(0.6);
        clientLevel4.setFlag(0);

        clientLevelList.add(clientLevel1);
        clientLevelList.add(clientLevel2);
        clientLevelList.add(clientLevel3);
        clientLevelList.add(clientLevel4);

        return ResponseData.success(clientLevelList);
    }



    @PostMapping(value = "judgeClientLevelName")
    @ResponseBody
    @ApiOperation(value = "2判断客户级别名称是否已存在接口", notes = "判断客户级别名称是否已存在", httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "新增成功"),
            @ApiResponse(code = 400, message = "新增失败")}
    )
    public ResultData judgeClientLevelName(@RequestBody @ApiParam(name = "ClientLevel", value = "输入级别名称，判断是否已存在", required = true) ClientLevel clientLevel) {

        System.out.println("客户级别名称：" + clientLevel.getClientLevelName());

        int count = 0;
        if (count == 0){
            return ResponseData.success("允许添加！");
        }else {
            return ResponseData.error(400,"已有同名级别！");
        }
    }



    @PostMapping(value = "addClientLevel")
    @ResponseBody
    @ApiOperation(value = "3新增客户级别接口", notes = "把客户级别信息存放在数据库中", httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "新增成功"),
            @ApiResponse(code = 400, message = "新增失败")}
    )
    public ResultData addClientLevel(@RequestBody @ApiParam(name = "ClientLevel", value = "输入级别名称和折扣", required = true) ClientLevel clientLevel) {


        String clientLevelName = clientLevel.getClientLevelName();
        Double clientDiscount = clientLevel.getClientDiscount();

        System.out.println("客户级别名称：" + clientLevelName);
        System.out.println("客户折扣：" + clientDiscount);

        int count = 1;
        if (count == 1){
            return ResponseData.success(count);
        }else {
            return ResponseData.error(400,"新增失败！");
        }
    }



    @PostMapping(value = "/updateClientLevel")
    @ResponseBody
    @ApiOperation(value = "4修改客户级别接口",notes = "编辑客户级别信息",httpMethod = "POST",response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResultData updateClientLevel(@RequestBody @ApiParam(name = "ClientLevel",value = "传入id，名称，折扣",required = true) ClientLevel clientLevel){

        int clientLevelId = clientLevel.getClientLevelId();
        String clientLevelName = clientLevel.getClientLevelName();
        Double clientDiscount = clientLevel.getClientDiscount();

        System.out.println("客户级别id：" + clientLevelId);
        System.out.println("客户级别名称：" + clientLevelName);
        System.out.println("客户折扣：" + clientDiscount);

        int count = 1;
        if (count == 1){
            return ResponseData.success(count);
        }else {
            return ResponseData.error(400,"修改失败");
        }
    }


    @PostMapping(value = "/judgeClientLevelHasClient")
    @ResponseBody
    @ApiOperation(value = "5判断客户是否有此级别接口",notes = "判断客户是否有此级别",httpMethod = "POST",response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResultData judgeClientLevelHasClient(@RequestBody @ApiParam(name = "Client",value = "传客户级别id，进行判断",required = true) Client client){

        int clientLevelId = client.getClientLevelId();

        System.out.println("客户级别id：" + clientLevelId);

        int count = 0;
        if (count == 0){
            return ResponseData.success("允许删除！");
        }else {
            return ResponseData.error(400,"需要将此级别下的客户转移至其他级别！");
        }
    }



    @PostMapping(value = "/delClientLevel")
    @ResponseBody
    @ApiOperation(value = "6删除客户级别接口",notes = "删除客户级别信息",httpMethod = "POST",response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResultData delClientLevel(@RequestBody @ApiParam(name = "ClientLevel",value = "根据id，删除客户级别信息",required = true) ClientLevel clientLevel){

        int clientLevelId = clientLevel.getClientLevelId();
        System.out.println("需要删除的客户级别id" + clientLevelId);
        int newClientLevelId = clientLevel.getNewClientLevelId();
        System.out.println("转移至新的客户级别id：" + newClientLevelId);

        int count = 1;
        if (count == 1){
            return ResponseData.success(count);
        }else {
            return ResponseData.error(400,"删除失败！");
        }
    }

}
